import React from 'react';
import ReactDOM from 'react-dom';

import store from './store'

import { addAction, subAction } from './action'
class MyCom extends React.Component { 
  state = { 
    num: 1,
    age:100
  }

  componentDidMount() {
		store.subscribe(() => {
			console.log('subscribe', store.getState())
			this.setState({}) // 通知视图去更新
		})
  }
  add = () => {
    store.dispatch(addAction())
  }

	sub = () => {
    store.dispatch(subAction())
  }
  
  render () {
    return (<div>
			{store.getState().num}
      <button onClick={this.add}>发送action-add1</button>
      <button onClick={this.sub}>发送action-sub</button>
			</div>)
  }
} 



ReactDOM.render(<div>
  <MyCom/>
</div>, 
document.getElementById('root')) 
